package com.docMan.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ws.rs.FormParam;

public class Page<T> implements Serializable {
	@FormParam("everyPage")
	private int everyPage=15;
	@FormParam("totalCount")
	private int totalCount;
	@FormParam("totalPage")
	private int totalPage;
	@FormParam("currentPage")
	private int currentPage=1;
	@FormParam("beginIndex")
	private int beginIndex;
	@FormParam("hasNextPage")
	private boolean hasNextPage;
	@FormParam("hasPrePage")
	private boolean hasPrePage;
	private String order;
	@FormParam("params")
	private Map<String, Object> params=new HashMap<String, Object>();
	@FormParam("endDate")
	private Date endDate;
	@FormParam("startDate")
	private Date startDate;
	@FormParam("name")
	private String name;
	@FormParam("ip")
	private String ip;
	private String lwdw="";
	private String searchText="";
	private String tm;
	private boolean success=true;
	private String message="";
	private List<T> result;
	private List<String> paramsOrder=new ArrayList<String>();
	private String orderByTime="desc";
	public Page(int everyPage, int totalCount, int totalPage, int currentPage,
			int beginIndex, boolean hasPrePage, boolean hasNextPage) {
		this.everyPage = everyPage;
		this.totalCount = totalCount;
		this.totalPage = totalPage;
		this.currentPage = currentPage;
		this.beginIndex = beginIndex;
		this.hasPrePage = hasPrePage;
		this.hasNextPage = hasNextPage;
	}
	

	public String getSearchText() {
		return searchText;
	}


	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}


	public String getLwdw() {
		return lwdw;
	}


	public void setLwdw(String lwdw) {
		this.lwdw = lwdw;
	}


	public String getOrderByTime() {
		return orderByTime;
	}


	public void setOrderByTime(String orderByTime) {
		this.orderByTime = orderByTime;
	}


	public String getName() {
		return name;
	}


	public void setName(String name) {
		this.name = name;
	}


	public String getIp() {
		return ip;
	}


	public void setIp(String ip) {
		this.ip = ip;
	}


	public String getTm() {
		return tm;
	}


	public void setTm(String tm) {
		this.tm = tm;
	}


	public Date getEndDate() {
		return endDate;
	}


	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}


	public Date getStartDate() {
		return startDate;
	}


	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}


	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<String> getParamsOrder() {
		return paramsOrder;
	}



	public void setParamsOrder(List<String> paramsOrder) {
		this.paramsOrder = paramsOrder;
	}



	public String getOrder() {
		return order;
	}


	
	public void setOrder(String order) {
		this.order = order;
	}



	public Map<String, Object> getParams() {
		return params;
	}
	
	public void setParams(Map<String, Object> params) {
		this.params = params;
	}

	public List<T> getResult() {
		return result;
	}

	public void setResult(List<T> result) {
		this.result = result;
	}

	public Page() {
		super();
	}

	public int getEveryPage() {
		return everyPage;
	}

	public void setEveryPage(int everyPage) {
		this.everyPage = everyPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getBeginIndex() {
		return beginIndex;
	}

	public void setBeginIndex(int beginIndex) {
		this.beginIndex = beginIndex;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public boolean isHasPrePage() {
		return hasPrePage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}
	
	public void initPage(int everyPage,int totalCount,int currentPage){
		
		setTotalCount(totalCount);
		setEveryPage(everyPage);
		setCurrentPage(currentPage==0?1:currentPage);
		int totalPage=0;
		if(totalCount%everyPage==0){
			totalPage=totalCount/everyPage;
		}else {
			totalPage=totalCount/everyPage+1;
		}
		setTotalPage(totalPage);
		setBeginIndex((getCurrentPage()-1)*everyPage);
		setHasPrePage(currentPage==1?false:true);
		setHasNextPage(currentPage==getTotalPage()|| totalPage==0?false:true);
		
	}
	
	
	public String getParamString(){
		String builder=new String();
		for (String key : params.keySet()) {
			builder+=key+":"+params.get(key);
		}
		return builder;
				 
	}
}
